package Test.ThreadLocalDemo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author pengshuai
 * @date 2022/3/12 23:26
 */
public class ThreadLocalUtils {

    public static final ThreadLocal<List<Object>> threadLocal = new ThreadLocal<>();

    public static final ThreadLocal<Map<String, Object>> threadLocalMap = new ThreadLocal<>();


    public void initObjectList() {
        threadLocal.set(new ArrayList<>());
    }


    public void setObjectList(Object o) {
        List<Object> list = threadLocal.get();

        if (list == null) {
            list = new ArrayList<>();
            threadLocal.set(list);
        }
        list.add(o);
    }


    public List<Object> getObjectList() {
        return threadLocal.get();
    }


    public void clearObjectList() {
        threadLocal.remove();
    }


}
